package com.sjgs.gis.web.rest;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.Application;
import com.sjgs.gis.service.EurekaService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api")
public class EurekaResouce {


    private final EurekaService eurekaService;

    public EurekaResouce(EurekaService eurekaService) {
        this.eurekaService = eurekaService;
    }

    @GetMapping(value = "/eureka/instances/{app}",produces = MediaType.APPLICATION_JSON_VALUE)
    public List<InstanceInfo> getInstancesByName(@PathVariable("app") String app){
        return eurekaService.getAppInstances(app);
    }

    @GetMapping(value = "/eureka/applications",produces = MediaType.APPLICATION_JSON_VALUE)
    public List<Application> getApplications(){
        return eurekaService.getApps();
    }
}
